import CryptoJS from 'crypto-js'

export function hash(input) {
  return parseInt(CryptoJS.SHA256(input).toString().substr(0, 8), 16)
}

export const meta = [
  ['red', 400],
  ['pink', 300],
  ['purple', 300],
  ['deepPurple', 300],
  ['indigo', 300],
  ['blue', 500],
  ['lightBlue', 600],
  // ['cyan', 700],
  // ['teal', 500],
  ['green', 600],
  ['lightGreen', 700],
  ['lime', 900],
  ['orange', 800],
  ['deepOrange', 500],
  ['brown', 300],
  ['blueGrey', 400],
  ['grey', 600],
  ['yellow', 1000],
  ['amber', 1000]
]

export function buildColors(meta) {
  const colors = []
  for (const line of meta) {
    const [name, div] = line
    for (let i = 100; i <= 900; i += 100) {
      colors.push({
        color: `${name}${i}`,
        text: (i < div) ? '#fff' : '#000'
      })
    }
  }
  return colors
}

const colors = buildColors(meta)

export function textToColor(text) {
  const h = hash(text)
  return colors[h % colors.length]
}
